using JetBrains.Annotations;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Rework.CommerceHistory.Models;
using Orchard.Localization;
using Orchard.ContentManagement;

namespace Rework.CommerceHistory.Handlers {
    [UsedImplicitly]
    public class CommercePayPalSettingsHandler : ContentHandler {
        public CommercePayPalSettingsHandler(IRepository<CommercePayPalSettingsPartRecord> repository) {
            T = NullLocalizer.Instance;
            Filters.Add(StorageFilter.For(repository));
            Filters.Add(new ActivatingFilter<CommercePayPalSettingsPart>("Site")); // I believe this adds the module onto the settings menu
            // Using driver instead
            //Filters.Add(new TemplateFilterForRecord<CommercePayPalSettingsPartRecord>("RegistrationSettings", "Parts/Commerce.PayPalSettings", "PayPal"));
        }

        public Localizer T { get; set; }

        // I believe this adds a new menu onto the settings folder
        protected override void GetItemMetadata(GetContentItemMetadataContext context) {
            if (context.ContentItem.ContentType != "Site")
                return;
            base.GetItemMetadata(context);
            context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("PayPal Settings")) {
                Id = "PayPalSettings",
                Name = T("PayPal Settings"),
                Position = "4"
            });
        }

    }
}
